﻿namespace Algo
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;

    using JetBrains.Annotations;

    public static class DichotomySearchExtensions
    {
        public static bool Find<T>([NotNull] this IDichotomySearchStrategy searchStrategy, [NotNull] IList<T> list, T item, [NotNull] IComparer<T> comparer, out int? prev, out int? next)
        {
            Contract.Requires<ArgumentNullException>(searchStrategy != null);
            Contract.Requires<ArgumentNullException>(list != null);
            Contract.Requires<ArgumentNullException>(comparer != null);
            
            return searchStrategy.Find(list, item, comparer, EmptyExtensions.Instance, out prev, out next);
        }

        public static bool Find<T>([NotNull] this IDichotomySearchStrategy searchStrategy, [NotNull] IList<T> list, T item, [NotNull] IAlgoExtensions extensions, out int? prev, out int? next)
        {
            Contract.Requires<ArgumentNullException>(searchStrategy != null);
            Contract.Requires<ArgumentNullException>(list != null);
            Contract.Requires<ArgumentNullException>(extensions != null);

            return searchStrategy.Find(list, item, Comparer<T>.Default, extensions, out prev, out next);
        }

        public static bool Find<T>([NotNull] this IDichotomySearchStrategy searchStrategy, [NotNull] IList<T> list, T item, out int? prev, out int? next)
        {
            Contract.Requires<ArgumentNullException>(searchStrategy != null);
            Contract.Requires<ArgumentNullException>(list != null);

            return searchStrategy.Find(list, item, Comparer<T>.Default, EmptyExtensions.Instance, out prev, out next);
        }
    }
}